
/* 血条 */
t1 = setInterval(function () {
    var bloodObj = document.querySelector('.num')
    var bloodWidth = parseInt(bloodObj.style.width)
    bloodWidth -= 10
    bloodObj.style.width = bloodWidth + 'px'
    if (bloodWidth == -10) {
        clearInterval(t1)
        clearInterval(t2)
        alert('结束了')
    }
}, 1000)


//点击重新开始按钮
var btnObj = document.querySelector('button')
btnObj.onclick = function () {
    var bloodObj = document.querySelector('.num')
    bloodObj.style.width = '200px'
    var bloodWidth = parseInt(bloodObj.style.width)
    
}


//随机数函数
function random(max, min) {
    return Math.floor(Math.random() * (max - min + 1) + min)
}

//随机出现星星，造星星，追加到页面
t2 = setInterval(function (evt) {
    var imgObj = document.createElement('img')
    imgObj.src = './star.gif'
    var min = 20
    var max = 100
    imgObj.width = random(max,min)
    imgObj.style.position = 'absolute'
    var min = 0
    var max = (window.innserWidth || document.documentElement.clientWidth) - imgObj.width
    imgObj.style.left =  random(max,min) + 'px'
    var max = (window.innerHeight || document.documentElement.clientHeight) - imgObj.width
    imgObj.style.top =  random(max,min) + 'px'

    document.body.appendChild(imgObj)

/* 点击删除星星 */
    document.body.onclick = function (evt) {
        var e = evt || window.event
        var target = e.target || e.srcElement
        if (target.nodeName == 'IMG') {
            document.body.removeChild(target)
            var bloodObj = document.querySelector('.num')
            var bloodWidth = parseInt(bloodObj.style.width)
            bloodWidth += 10
            bloodObj.style.width = bloodWidth + 'px'
            if (bloodWidth > 200) {
                bloodWidth = 200
                bloodObj.style.width = bloodWidth + 'px'
                console.log(bloodWidth);

            }
        }


    }
}, 1000)

